package com.tdcoding.chat.entities;

import io.netty.channel.Channel;

import java.io.Serializable;

import com.tdcoding.chat.constants.MainConstants;

public class ChannelInfo implements Serializable {
	private static final long serialVersionUID = 1L;
	private int status; // 0正常；1隐身；2离开；3忙碌；4勿打扰；5离线

	private int platform; // 登录平台：0网站；1应用（win,mac,linux）；2无线（android,iphone,wphone,ipad）
	private long userId;
	private String nickName;
	private String userName;
	private String userHead;
	private String password;
	private Channel chatChannel;
	private Channel fileChannel;

	public int getStatus() {
		return status;
	}

	public void setStatus(int status) {
		this.status = status;
	}

	public int getPlatform() {
		return platform;
	}

	public void setPlatform(int platform) {
		this.platform = platform;
	}

	public long getUserId() {
		return userId;
	}

	public void setUserId(long userId) {
		this.userId = userId;
	}
	
	public String getNickName() {
		return nickName;
	}

	public void setNickName(String nickName) {
		this.nickName = nickName;
	}

	public String getUserName() {
		return userName;
	}

	public void setUserName(String userName) {
		this.userName = userName;
	}

	public String getUserHead() {
		return userHead;
	}

	public void setUserHead(String userHead) {
		this.userHead = userHead;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public Channel getChatChannel() {
		return chatChannel;
	}

	public void setChatChannel(Channel chatChannel) {
		this.chatChannel = chatChannel;
	}

	public Channel getFileChannel() {
		return fileChannel;
	}

	public void setFileChannel(Channel fileChannel) {
		this.fileChannel = fileChannel;
	}

	/**
	 * 回收channel 0全部；1聊天；2文件
	 */
	public void realseChannel(int channelType) {
		switch (channelType) {
			case MainConstants.CHANNEL_TYPE_CHAT:
				if (chatChannel != null) {
					chatChannel.close();
					chatChannel = null;
				}
				break;
			case MainConstants.CHANNEL_TYPE_FILE:
				if (fileChannel!=null) {
					fileChannel.close();
					fileChannel = null;
				}
				break;
			default:
				if (chatChannel != null) {
					chatChannel.close();
					chatChannel = null;
				}
				if (fileChannel!=null) {
					fileChannel.close();
					fileChannel = null;
				}
		}
	}

	@Override
	public String toString() {
		return "ChannelInfo [status=" + status + ", platform=" + platform + ", userId=" + userId + ", nickName="
				+ nickName + ", userName=" + userName + ", userHead=" + userHead + ", password=" + password
				+ ", chatChannel=" + chatChannel + ", fileChannel=" + fileChannel + "]";
	}
	
}
